package com.foreknow.demo03;

// 银行系统
import java.util.Scanner;

public class Bank {

    public static void main(String[] args) {
        int [] array = {10000}; //定义10000余额
        String name = "dd";     //定义用户名
        String password = "123";//定义密码
        String answer = "y";    //定义是否循环
        boolean denglu = true;
        int choice = 0;
        int cunkuan = 0;//存款金额
        int qukuan = 0;//取款金额
        do {

                System.out.println("--------------------------------");
                System.out.println("************ 欢迎登陆   *********");
                System.out.println("********* 中国人民银行   *********");
                System.out.println("************     版本1.0 *******");
                System.out.println("--------------------------------");
                Scanner input = new Scanner(System.in);
               denglu = true;
               if (denglu){
                   for (int i = 1;i<4;i++){
                       System.out.println("请输入用户名：");
                       name = input.next();
                       System.out.println("请输入密码：");
                       password = input.next();
                       if (name.equals("dd")&&password.equals("123")){
                           System.out.println("登录成功！！！！");
                           System.out.println("1.查询余额  2.存款  3.取款  4.修改密码  5.退出");
                           System.out.println("请输入菜单(1-5)：");
                            choice = input.nextInt();
                               switch(choice){

                                   case 1:
                                       System.out.println("您的余额为" + array[0]);
                                       break;
                                   case 2:
                                        answer = "y";
                                       do {
                                           System.out.println("请输入您要存款的金额：");
                                           cunkuan = input.nextInt();
//                                       System.out.println("存款成功，当前余额为：" + (array[0] + cunkuan));
                                           if (cunkuan>10000){
                                               System.out.println("单次存款金额超过10000");
                                               System.out.println("是否继续操作(y/n)：");
                                               answer = input.next();
                                           }
                                           if (cunkuan<0){
                                               System.out.println("存款金额错误");
                                               System.out.println("是否继续操作(y/n)：");
                                               answer = input.next();
                                           }
                                           if (cunkuan%100 !=0){
                                               System.out.println("请输入100的整数倍存款");
                                               System.out.println("是否继续操作(y/n)：");
                                               answer = input.next();
                                           }if((cunkuan<=10000)&&(cunkuan>0)&&(cunkuan%100==0)){
                                               System.out.println("存款成功，当前余额为：" + (array[0] + cunkuan));
                                               break;
                                           }

                                       }while(answer.equals("y"));
                                       break;
                                   case 3:
                                       answer = "y";
                                       do {
                                           System.out.println("请输入你要取款的金额：");
                                           qukuan = input.nextInt();
                                           if (qukuan>array[0]){
                                               System.out.println("余额不足");
                                               System.out.println("是否继续操作(y/n)：");
                                               answer = input.next();
                                           }
                                           if (qukuan>3000){
                                               System.out.println("单次取款金额超过3000");
                                               System.out.println("是否继续操作(y/n)：");
                                               answer = input.next();
                                           }
                                           if (qukuan<0){
                                               System.out.println("取款金额错误");
                                               System.out.println("是否继续操作(y/n)：");
                                               answer = input.next();
                                           }
                                           if (qukuan%100!=0){
                                               System.out.println("请存100的整数倍金额");
                                               System.out.println("是否继续操作(y/n)：");
                                               answer = input.next();
                                           }
                                           if (qukuan<=3000&&qukuan>0&&qukuan%100==0){
                                               System.out.println("存款成功，当前余额为" + (array[0] - qukuan));
                                               break;
                                           }

                                       }while(answer.equals("y"));
                                       break;
                                   case 4:
                                       answer = "y";
                                       do {
                                           String password1 = "";//第一次新密码
                                           String password2 = "";//第二次新密码
                                           System.out.println("请输入旧密码：");
                                           password = input.next();
                                           System.out.println("请输入新密码：");
                                           password1 = input.next();
                                           System.out.println("请再次输入新密码：");
                                           password2 = input.next();
                                           if (!(password1.equals(password2))){
                                               System.out.println("两次输入密码不一致，请重新输入");
                                               System.out.println("当前密码为：" + password);
                                               System.out.println("是否继续操作(y/n):");
                                               answer = input.next();
                                           }
                                           if (password1.equals(password2)){
                                               System.out.println("密码修改成功");
                                               password = password1;
                                               System.out.println("当前密码为" + password);
                                               break;
                                           }
                                       }while(answer.equals("y"));
                                       break;
                                   case 5:
                                       answer = "n";
                                       System.out.println("退出成功！！！！！");
                                       break;
                               }
                               break;
                       }else if (i<3){
                           System.out.println("输入错误，还有" + (3-i) + "次机会");
                       }else{
                           System.out.println("输入3次错误，吞卡，请找老司机帮忙");
                       }
                   }
               }
            System.out.println("是否继续(y/n)：");
            answer = input.next();
        }while(answer.equals("y"));

    }
}
